package cn.java83.zsb.springcloudserve.service;

import cn.java83.zsb.springcloudserve.entity.Advtise;
import cn.java83.zsb.springcloudserve.mapper.AdvMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
public class AdvService extends ServiceImpl<AdvMapper,Advtise>  implements IService<Advtise> {



    public cn.java83.zsb.springcloudserve.entity.Page<Advtise> search(int pageno, int pageSize, String title, Date start, Date end){

        Page<Advtise> page = Page.of(pageno, pageSize);
        LambdaQueryWrapper<Advtise> q=new LambdaQueryWrapper<>();
        q.like(!StringUtils.isEmpty(title),Advtise::getTitle,title);
        q.ge(start!=null,Advtise::getStarttime,start);
        q.le(end!=null,Advtise::getStarttime,end);
        Page<Advtise> pageInfo = page(page, q);
        return new cn.java83.zsb.springcloudserve.entity.Page<Advtise>(pageInfo.getRecords(),(int)page.getCurrent(),(int)pageInfo.getTotal(),pageSize);
    }
}
